package com.imooc.LinkedList.removeLinkedListElements;

/**
 * 删除值，使用递归算法
 */
public class Solution3 {

    public ListNode removeElements(ListNode head, int val) {
        if(head == null)
            return null;
//        ListNode res = removeElements(head.next, val);
//        if(head.val == val) {
//            return res;
//        }else {
//            head.next = res;
//            return head;
//        }
        head.next = removeElements(head.next, val);
        return head.val == val ? head.next : head;
    }

    public static void main(String[] args) {
        int[] arr = {1,2,3,3,3,5,6,3};
        ListNode head = new ListNode(arr);
        System.out.println(head);
        Solution3 solution = new Solution3();
        solution.removeElements(head, 3);
        System.out.println(head);
    }
}
